/*
 *   MetrixViewer - A simple app for viewer Metrix data. Uses XML data from Webosroundup's Metrix data and graphs it using Google charts API.
 *   http://code.google.com/p/metrixviewer/
 *   Copyright (C) 2010  Wes Brown
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 


MetrixViewer = {};


//Cookie for apps
MetrixViewer.appsCookie = new Mojo.Model.Cookie('apps');
MetrixViewer.appsCookieObject = MetrixViewer.appsCookie.get();

//Cookie for custom metrics
MetrixViewer.customCookie = new Mojo.Model.Cookie('custom');
MetrixViewer.customCookieObject = MetrixViewer.customCookie.get();


//Current selection
MetrixViewer.appname = "";
MetrixViewer.packageId = "";




function StageAssistant() {

}

StageAssistant.prototype.setup = function() {

	MetrixViewer.Metrix = new Metrix(); 

	//Start first scene
	this.controller.pushScene("main");

};



//Global functions
var getCustomMetric = function(fullList, packageId, customNum) {

	var metric = "";
	
	for(var i = 0; i < fullList.length; i++) {
	
		if((fullList[i].packageId == packageId)&&(fullList[i].customNum == customNum)){
			metric = fullList[i].metric;
		}
	
	}

	return metric;

}

var addCustomMetric = function(fullList, packageId_in, custom1, custom2, custom3, custom4) {

	var returnList = [], s = {};
	var packageExists = false;
	
	for(var i = 0; i < fullList.length; i++){
		s = {};
		s = fullList[i];
	
		if((s.packageId == packageId_in)&&(s.customNum == 1)){
			s.metric = custom1;
			packageExists = true;
		} else if((s.packageId == packageId_in)&&(s.customNum == 2)){
			s.metric = custom2;
			packageExists = true;
		} else if((s.packageId == packageId_in)&&(s.customNum == 3)){
			s.metric = custom3;
			packageExists = true;
		} else if((s.packageId == packageId_in)&&(s.customNum == 4)){
			s.metric = custom4;
			packageExists = true;
		} 
		
		returnList.push(s);
	
	}
	
	if(packageExists == false) {
		
		returnList.push({"packageId": packageId_in, "customNum": 1, "metric": custom1});
		returnList.push({"packageId": packageId_in, "customNum": 2, "metric": custom2});
		returnList.push({"packageId": packageId_in, "customNum": 3, "metric": custom3});
		returnList.push({"packageId": packageId_in, "customNum": 4, "metric": custom4});
		
	}
	
	return returnList;

}